package com.pro.handler;

import com.alibaba.fastjson.JSON;
import com.pro.pojo.ResponseResult;
import com.pro.utils.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * ClassName:AuthenticationException
 * Package:com.example.handler
 * Description:
 *
 * @Date:2021/12/27 15:34
 * @Author: ZPT
 */
@Component
public class AuthenticationException implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, org.springframework.security.core.AuthenticationException authException) throws IOException, ServletException {
        ResponseResult result = new ResponseResult(HttpStatus.UNAUTHORIZED.value(), "用户认证失败请查询登录");
        String json = JSON.toJSONString(result);
        WebUtils.renderString(response,json);
    }
}
